package com.nulldev.util.data.FastMath;

import java.io.Closeable;
import java.lang.reflect.Method;

import javax.crypto.spec.SecretKeySpec;

class PortKey implements Closeable {
	static final Method destroyKey;

	static {
		Method _destroyKey = null;
		try {
			_destroyKey = SecretKeySpec.class.getMethod("destroy");
		} catch (Exception ex) {
		}
		destroyKey = _destroyKey;
	}

	static void destroy(SecretKeySpec key) {
		if (key != null && destroyKey != null) {
			try {
				destroyKey.invoke(key);
			} catch (Exception ex) {
			}
		}
	}

	public final SecretKeySpec data;

	public PortKey(SecretKeySpec _data) {
		data = _data;
	}

	@Override
	public void close() {
		destroy(data);
	}
}
